#include "wn_jni_hack.h"
#include <string.h>
#include <jni.h>
#include <wn.h>
#include "AsciiWordNetImpl.h"
#include "wn_java.h"

jint Java_edu_princeton_cogsci_wn_ascii_AsciiWordNetImpl_lookupSense
( JNIEnv* env, jobject obj, jstring jkey )
{
  wninit( );

  const char* key_ = env->GetStringUTFChars( jkey, 0 );
  char* key = strdup( key_ );
  SnsIndexPtr senseIndex = GetSenseIndex( key );

  jint sense;
  if ( senseIndex == NULL )
    sense = 0;
  else
    sense = senseIndex->wnsense;

  FreeSenseIndex( senseIndex );
  delete key;
  env->ReleaseStringUTFChars( jkey, key_ );

  return sense;
}
